<!--
 * @Author: ChenCaoYang
 * @Date: 2021-05-26 22:15:29
 * @LastEditors: chencaoyang
 * @LastEditTime: 2021-06-15 15:26:47
-->
<template>
  <div class="container">
    <div class="user_conter">
      <!-- 用户信息 -->
      <div class="user_info">
        <div class="user_info_content">
          <div class="header">
            <img src="@/assets/imgs/cart-empty.png" alt="" />
          </div>
          <div class="info">
            <p>{{ userinfo.userName }}</p>
            <p v-if="userinfo.userPhone">{{ userinfo.userPhone }}</p>
          </div>
        </div>
      </div>
      <!-- 商品管理栏 -->
      <div class="product_info">
        <div class="product">
          <div @click="toCards(2)">
            <i class="el-icon-s-claim"></i>
            待收货
            <span v-if="orderStatus.deliverNums"
              >({{ orderStatus.deliverNums }}})</span
            >
          </div>
          <div @click="toCards(3)">
            <i class="el-icon-alarm-clock"></i>
            退款
            <span v-if="orderStatus.returnNums"
              >({{ orderStatus.returnNums }})</span
            >
          </div>
          <div @click="toCards(1)">
            <i class="el-icon-date"></i>
            我的订单
            <span v-if="orderStatus.nums">({{ orderStatus.nums }})</span>
          </div>
        </div>
        <div class="my_address" @click="toMyAddress()">我的收货地址</div>
      </div>
      <el-divider></el-divider>
      <!-- 猜你喜欢 -->
      <div class="you_like">
        <h4>猜你喜欢</h4>
        <div class="you_like_content">
          <div
            v-for="(item, index) in productData"
            :key="index"
            @click="togoodsDetail(item.id)"
          >
            <div class="product_image">
              <img :src="item.titlePicStr" />
            </div>
            <div class="product_info">
              <p>{{ item.productName }}</p>
              <span class="yishou">已售{{ item.saleNums }}</span>
              <span class="price">￥{{ item.productPriceMax }}</span>
            </div>
          </div>
        </div>
        <!-- 分页 -->
        <div class="footer">
          <el-pagination
            prev-text="上一页"
            next-text="下一页"
            background
            layout="prev, pager, next"
            :total="total"
            :page-size="9"
            hide-on-single-page
            @current-change="currentChange"
          >
          </el-pagination>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { get_data } from "../../../../utils/utils";
export default {
  name: "UserCenter",
  data() {
    return {
      userinfo: {},
      productData: [],
      pageParam: {
        page: 1,
        rows: 12,
      },
      total: 0,
      orderStatus: {},
    };
  },
  created() {
    if (get_data("userInfo")) {
      this.userinfo = JSON.parse(get_data("userInfo"));
    } else {
      this.$router.push({
        path: "/login",
      });
      return;
    }
    this.getRecommendProduct();
    this.getOrderStatus();
  },
  methods: {
    togoodsDetail(id) {
      this.$router.push({
        path: "/goods/details",
        query: {
          id,
        },
      });
    },
    getOrderStatus() {
      this.$http
        .fetch(this.$apiPath.getOrderStatus, {
          method: "get",
        })
        .then((res) => {
          this.orderStatus = res.data;
        });
    },
    currentChange(current) {
      this.pageParam.page = current;
      this.getRecommendProduct();
    },
    getRecommendProduct() {
      this.$http
        .fetch(this.$apiPath.getRecommendProduct, {
          method: "get",
          params: this.pageParam,
        })
        .then((res) => {
          this.productData = res.data.records;
          this.total = res.data.total;
        });
    },
    toCards(index) {
      let userInfo = get_data("userInfo");
      userInfo = JSON.parse(userInfo);
      console.log(userInfo);
      this.$router.push({
        path: "/order/userCards?id=" + userInfo.id + "&active=" + index,
      });
    },
    toMyAddress() {
      this.$router.push({
        path: "/order/address",
      });
    },
  },
};
</script>

<style lang="less" scoped>
.container {
  width: 100%;
  .user_conter {
    padding: 30px 20px;
    .user_info {
      //   padding: 30px 20px;
      .user_info_content {
        height: 80px;
        display: flex;
        align-items: center;
        .header {
          width: 80px;
          height: 100%;
          img {
            width: 100%;
            height: 100%;
          }
        }
        .info {
          height: 54px;
          font-family: Source Han Sans CN;
          margin-left: 29px;
          p:first-child {
            font-size: 18px;
            font-weight: bold;
            color: #333333;
            margin-bottom: 13px;
          }
          p:last-child {
            font-size: 14px;
            font-weight: 400;
            color: #666666;
          }
        }
      }
    }
    .product_info {
      margin-top: 30px;
      //   height: 50px;
      .product {
        height: 20px;
        width: 752px;
        display: flex;
        justify-content: center;
        align-items: center;
        & > div {
          width: 33.333%;
          text-align: center;
          font-size: 16px;
          font-family: Source Han Sans CN;
          font-weight: 400;
          color: #666666;
          cursor: pointer;
          span {
            color: #cf975a;
          }
        }
        & > div:first-child {
          text-align: left;
        }
        & > div:last-child {
          text-align: right;
        }
        & > div:not(:last-child) {
          border-right: 2px solid #666666;
        }
      }
      .my_address {
        font-size: 16px;
        font-family: Source Han Sans CN;
        font-weight: 400;
        color: #cf975a;
        float: right;
        margin-top: -20px;
        cursor: pointer;
      }
    }
    .you_like {
      h4 {
        margin-bottom: 20px;
      }
      .you_like_content {
        & > div {
          width: 282px;
          height: 365px;
          border: 1px solid #e7e7e7;
          display: inline-block;
          margin-right: 8px;
          cursor: pointer;
          margin-bottom: 10px;
          .product_image {
            height: 267px;
            margin-bottom: 10px;
            img {
              width: 100%;
              height: 100%;
            }
          }
          .product_info {
            margin-top: 0;
            padding: 0 19px 18px 19px;
            font-size: 16px;
            font-weight: 400;
            position: relative;
            p {
              margin-bottom: 24px;
              font-family: PingFangSC;
              color: #333333;
              line-height: 18px;
              overflow: hidden;
              text-overflow: ellipsis;
              display: -webkit-box;
              -webkit-line-clamp: 2;
              -webkit-box-orient: vertical;
            }
            .yishou {
              font-size: 14px;
              font-family: PingFangSC;
              color: #999999;
            }
            .price {
              position: absolute;
              right: 20px;
              bottom: 17px;
              font-size: 19px;
              font-family: Source Han Sans CN;
              color: #f97534;
            }
          }
        }
        & > div:nth-child(4n) {
          margin-right: 0;
        }
      }
      .footer {
        padding: 0;
        margin: 0 auto;
        margin-top: 30px;
        margin-bottom: 33px;
        background-color: #ffffff;
        /deep/.btn-prev {
          width: 74px;
          height: 30px;
          border: 1px solid #c7c7c7;
          border-radius: 15px;
        }
        /deep/.btn-next {
          width: 74px;
          height: 30px;
          border: 1px solid #c7c7c7;
          border-radius: 15px;
          color: #999999;
        }
        /deep/.el-pager li {
          width: 30px;
          height: 30px;
          border: 1px solid #c7c7c7;
          border-radius: 15px;
          color: #999999;
        }
        /deep/.el-pager {
          .number {
            text-align: center;
            padding: 0;
          }
          .active {
            color: #fff;
          }
          //   .number:hover {
          //     color: #999999 !important;
          //   }
          li:not(.active).number:hover {
            color: #999999 !important;
          }
        }
        /deep/.el-pager li:not(.disabled).active {
          background-color: #cf975a;
        }
      }
    }
  }
}
</style>
